﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;
using LotteryVote.Entity;
using LotteryVote.Logic.Application;

namespace LotteryVote.Controls
{
    public partial class GamePlayWayList : System.Web.UI.UserControl
    {
        public int GamePlayWayId
        {
            get
            {
                return int.Parse(ddl_gameplayway.SelectedValue);
            }
            set
            {
                ddl_gameplayway.SelectedValue = value.ToString();
            }
        }
        public override string ClientID
        {
            get
            {
                return ddl_gameplayway.ClientID;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected override void OnInit(EventArgs e)
        {
            if (!IsPostBack)
                BindGamePlayWay();
            base.OnInit(e);
        }

        void BindGamePlayWay()
        {
            ddl_gameplayway.DataSource = LotterySystem.Current.GamePlayWay.Where(it => it.PlayWay.WayId != (int)PlayWayEnum.HeadAndLast)
                .Select(it => new
                {
                    GamePlayWayId = it.Id,
                    Name = it.GameType.GameName +
                        (string.IsNullOrEmpty(it.PlayWay.WayName) ? string.Empty : ("-->" + GetGlobalResourceObject("Resource", it.PlayWay.WayName)))
                });
            ddl_gameplayway.DataTextField = "Name";
            ddl_gameplayway.DataValueField = "GamePlayWayId";
            ddl_gameplayway.DataBind();
            ddl_gameplayway.Items.Insert(0, new ListItem(GetGlobalResourceObject("Resource", "All").ToString(), "0"));
        }
    }
}